package com.tanhua.autoconfig.template;

import com.baidu.aip.face.AipFace;
import com.tanhua.autoconfig.properties.AipFaceProperties;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;

public class AipFaceTemplate {
//检查图片是否包含人类
    @Autowired
    private AipFace client;
  public boolean face(String imageURL){
      // 调用接口
      String image = imageURL;
      String imageType = "URL";
      // 传入可选参数调用接口
      HashMap<String, String> options = new HashMap<String, String>();
      options.put("face_field", "age");
      options.put("max_face_num", "2");
      options.put("face_type", "LIVE");
      options.put("liveness_control", "LOW");

      // 人脸检测
      JSONObject res = client.detect(image, imageType, options);
      System.out.println(res.toString(2));
      String error_code =  String.valueOf(res.get("error_code"));
      if (error_code.equals("0")){
          return true;
      }else {
          return false;
      }

  }
}
